<template>
  <div class="hello">
    <h2>mutations</h2>
    <button @click="$store.commit('increment')">增加增加</button>
    <p>改变后的值：{{ $store.state.count }}</p>
    <button @click="$store.commit('incrementParams', 10)">传入一个参数demo-载荷方式</button>
    <p>传入参数后的值：{{ $store.state.countParams }}</p>
    <button
      @click="
        $store.commit({
          type: 'incrementObj',
          amount: 10
        })
      "
    >
      以对象的方式提交---$store.commit({
          type: 'incrementObj',
          amount: 10
        })
    </button>
    <p>传入参数后的值：{{ $store.state.countObj }}</p>
    <button style="color: red;" @click="incrementMap">在组件中提交 Mutation</button>
    <p>MAP改变的值：{{ $store.state.countMap }}</p>
  </div>
</template>

<script>
import { mapMutations } from 'vuex'
export default {
  name: 'HelloWorld',
  props: {
    msg: String
  },
  methods: {
    ...mapMutations(['incrementMap'])
  },
  computed: {}
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h3 {
  margin: 40px 0 0;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
